<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Title</title>
    <script src="../js/vue.js"></script>
</head>

<body>
    <div id="app">
        <!-- 为什么组件中的data是函数：
        为了多个相同组件的数据互相不受影响
     -->
        <cpn></cpn>
        <cpn></cpn>
        <cpn></cpn>
    </div>

    <template id="CPN">
        <div>
            <h2 @click="counter++">当前计数：：{{counter}}</h2>
            <button @click="sub">-</button>
            <button @click="add">+</button>
        </div>
    </template>

    <script>
        //1、注册组件
        Vue.component('cpn', ({
            template: '#CPN',
            data() {
                return {
                    counter: 0
                }
            },
            methods: {
                add() {
                    this.counter++;
                },
                sub() {
                    this.counter--;
                }
            }
        }))


        const vm = new Vue({
            el: '#app',
            data: {
                message: '我是你爹!'
            },
            methods: {}
        });
    </script>
</body>

</html>